<script setup lang="ts">
import { ref } from 'vue';
import { $t } from '@/locales';
import { enableStatusOptions } from '@/constants/business';
import { translateOptions } from '@/utils/common';

defineOptions({ name: 'RoleSearch' });

const activeName = ref(['role-search']);

interface Emits {
  (e: 'reset'): void;
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

const model = defineModel<Api.SystemManage.RoleSearchParams>('model', { required: true });

function reset() {
  emit('reset');
}

function search() {
  emit('search');
}
</script>

<template>
  <ElCard class="card-wrapper">
    <!-- <p>src/views/plugin/excel/index.vue</p> -->
    <ElCollapse v-model="activeName">
      <ElForm>
        <ElRow :gutter="24" align="middle" justify="center" class="items-center">
          <ElCol :lg="6" :md="8" :sm="12">
            <ElFormItem :label="$t('page.manage.role.roleName')" prop="roleName">
              <ElInput v-model="model.roleName" :placeholder="$t('page.manage.role.form.roleName')" />
            </ElFormItem>
          </ElCol>
          <ElCol :lg="6" :md="8" :sm="12">
            <ElFormItem :label="$t('page.manage.role.roleCode')" prop="roleCode">
              <ElInput v-model="model.roleCode" :placeholder="$t('page.manage.role.form.roleCode')" />
            </ElFormItem>
          </ElCol>
          <ElCol :lg="6" :md="8" :sm="12">
            <ElFormItem :label="$t('page.manage.role.roleStatus')" prop="status">
              <ElSelect v-model="model.status" :placeholder="$t('page.manage.role.form.roleStatus')" clearable>
                <ElOption
                  v-for="{ label, value } in translateOptions(enableStatusOptions)"
                  :key="value"
                  :label="label"
                  :value="value"
                ></ElOption>
              </ElSelect>
            </ElFormItem>
          </ElCol>
          <ElCol :lg="6" :md="24" :sm="24">
            <ElFormItem>
              <ElSpace class="w-full justify-end flex items-center" alignment="center">
                <ElButton @click="reset">
                  <template #icon>
                    <icon-ic-round-refresh class="text-icon" />
                  </template>
                  {{ $t('common.reset') }}
                </ElButton>
                <ElButton type="primary" plain @click="search">
                  <template #icon>
                    <icon-ic-round-search class="text-icon" />
                  </template>
                  {{ $t('common.search') }}
                </ElButton>
              </ElSpace>
            </ElFormItem>
          </ElCol>
        </ElRow>
      </ElForm>
    </ElCollapse>
  </ElCard>
</template>

<style scoped>
.items-center {
  display: flex;
  align-items: center;
}

:deep(.el-form-item) {
  margin-bottom: 0;
}

:deep(.el-form-item__content) {
  display: flex;
  align-items: center;
}
</style>
